<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>套餐市场 - <?= $systemConfig['system_name'] ?? '' ?></title>
<link rel="stylesheet" href="/layui/css/layui.css">
<script src="/static/js/jquery.min.js"></script>
<script src="/layui/layui.js"></script>
<style>
*{margin:0;padding:0;box-sizing:border-box;}body{background:#f5f7fa;font-family:"Microsoft YaHei","PingFang SC",sans-serif;}
.header{background:#fff;box-shadow:0 1px 4px rgba(0,0,0,.08);}.header .inner{max-width:1200px;margin:0 auto;display:flex;align-items:center;justify-content:space-between;padding:0 20px;height:60px;}
.header .logo{font-size:20px;font-weight:700;color:#1e3c72;text-decoration:none;}.header .nav{display:flex;gap:16px;}
.header .nav a{color:#555;text-decoration:none;font-size:14px;padding:8px 12px;border-radius:4px;}.header .nav a:hover,.header .nav a.active{color:#1e9fff;background:#f0f7ff;}
.container{max-width:1000px;margin:0 auto;padding:20px;}.filter-bar{margin-bottom:20px;}
.package-card{background:#fff;border-radius:12px;padding:24px 28px;box-shadow:0 2px 12px rgba(0,0,0,.05);margin-bottom:14px;display:flex;justify-content:space-between;align-items:center;}
.package-card .info .name{font-size:18px;font-weight:600;color:#333;}.package-card .info .channel{color:#666;font-size:13px;margin-top:4px;}
.package-card .info .desc{color:#999;font-size:13px;margin-top:6px;}.package-card .meta{text-align:center;min-width:140px;}
.package-card .meta .price{font-size:26px;color:#ff5722;font-weight:700;}.package-card .meta .limit{color:#888;font-size:13px;margin-top:4px;}
.balance-hint{color:#1e9fff;font-size:12px;margin-top:4px;}
</style>
</head>
<body>
<div class="header"><div class="inner"><a href="/" class="logo"><?= $systemConfig['system_name'] ?? '' ?></a>
<div class="nav"><a href="/user/index/dashboard">控制台</a><a href="/user/index/packages" class="active">套餐市场</a><a href="/user/index/myApps">我的应用</a><a href="/user/index/callStats">调用统计</a><a href="/user/index/myOrders">我的订单</a><a href="/user/index/myPackages">已购套餐</a><a href="/user/index/recharge">余额充值</a><a href="/user/index/apiDoc">接入文档</a><a href="/user/index/profile"><?= $userInfo['nickname'] ?? $userInfo['username'] ?></a><a href="/user/index/logout">退出</a></div></div></div>
<div class="container">
<div class="filter-bar"><div class="layui-btn-container">
<a href="/user/index/packages" class="layui-btn layui-btn-sm <?= $channelId==0?'layui-btn-normal':'layui-btn-primary' ?>">全部</a>
<?php foreach($channels as $ch): ?><a href="/user/index/packages?channel_id=<?= $ch['id'] ?>" class="layui-btn layui-btn-sm <?= $channelId==$ch['id']?'layui-btn-normal':'layui-btn-primary' ?>"><?= $ch['name'] ?></a><?php endforeach; ?>
</div></div>
<?php if(!empty($packages)): foreach($packages as $pkg): ?>
<div class="package-card">
<div class="info"><div class="name"><?= $pkg['name'] ?></div><div class="channel"><?= $pkg['channel_name'] ?> · <?= $pkg['channel_type'] ?></div><?php if(!empty($pkg['description'])): ?><div class="desc"><?= $pkg['description'] ?></div><?php endif; ?></div>
<div class="meta"><div class="price">¥<?= number_format($pkg['price'], 2) ?></div><div class="limit">调用<?= $pkg['call_limit'] ?>次 · 有效期<?= $pkg['valid_days'] ?>天</div>
<?php if($userId): ?><button class="layui-btn layui-btn-sm layui-btn-normal" onclick="buyNow(<?= $pkg['id'] ?>, '<?= htmlspecialchars($pkg['name']) ?>', <?= $pkg['price'] ?>)" style="margin-top:8px;">立即购买</button>
<?php else: ?><a href="/user/index/login" class="layui-btn layui-btn-sm" style="margin-top:8px;">登录购买</a><?php endif; ?></div>
</div>
<?php endforeach; else: ?><div style="text-align:center;padding:60px;color:#999;">暂无上架套餐</div><?php endif; ?>
</div>
<div id="payModal" style="display:none;padding:20px;">
<p style="margin-bottom:12px;font-weight:600;color:#333;">选择支付方式 - <span id="pkgName"></span></p>
<p style="margin-bottom:12px;color:#ff5722;font-weight:600;">金额：¥<span id="pkgPrice"></span></p>
<div style="margin-bottom:10px;padding:12px;border:2px solid #1e9fff;border-radius:8px;cursor:pointer;background:#f0f7ff;" onclick="payByBalance()">
<b>💰 余额支付</b><span style="color:#999;font-size:12px;margin-left:8px;">当前余额 ¥<?= number_format($userInfo['balance'] ?? 0, 2) ?></span><span style="float:right;color:#1e9fff;">立即扣款 →</span>
</div>
<div style="margin-top:10px;color:#999;font-size:13px;border-bottom:1px solid #eee;padding-bottom:6px;margin-bottom:8px;">或选择在线支付</div>
<div id="payChannelList" style="max-height:200px;overflow-y:auto;">
<?php if(!empty($payChannels)): foreach($payChannels as $pc): ?>
<div style="padding:12px;border:1px solid #e6e6e6;border-radius:6px;margin-bottom:8px;cursor:pointer;" onclick="payByEpay(<?= $pc['id'] ?>)"><b><?= $pc['name'] ?></b><span style="color:#999;font-size:12px;margin-left:8px;"><?= $pc['pay_type']=='alipay'?'支持支付宝':($pc['pay_type']=='wxpay'?'支持微信支付':$pc['pay_type']) ?></span><span style="float:right;color:#1e9fff;">去支付 →</span></div>
<?php endforeach; else: ?><p style="color:#999;text-align:center;padding:10px;">暂无在线支付通道</p><?php endif; ?>
</div></div>
<script>
var currentPkgId=0,currentPkgPrice=0;
function buyNow(pkgId,pkgName,price){currentPkgId=pkgId;currentPkgPrice=price;$('#pkgName').text(pkgName);$('#pkgPrice').text(price.toFixed(2));layer.open({type:1,title:'确认支付',area:['500px','420px'],content:$('#payModal'),cancel:function(){currentPkgId=0;}});}
function payByBalance(){if(!currentPkgId)return;$.post('/user/index/buyPackage',{package_id:currentPkgId,pay_method:'balance'},function(r){layer.msg(r.msg,{icon:r.code===0?1:2});if(r.code===0){layer.closeAll();setTimeout(function(){location.reload();},1500);}});}
function payByEpay(channelId){if(!currentPkgId)return;location.href='/user/pay/go?package_id='+currentPkgId+'&pay_channel_id='+channelId;}
</script>
</body>
</html>